Skip to content

Map files to their corresponding compilation steps #2308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from

Conversation

arielherself
Copy link

This PR solves the problem discussed in #2305 by categorizing build context (packages, c_macros and include_dirs) into different “compilation units,” which hold modules and files required by a single compilation step.

When ZLS analyzes a symbol, it will find the context of the compilation unit that the current file belongs to. When there are multiple of them, it picks a random one. However, this could be improved by calculating the longest common prefix between the current file and the root file of the compilation unit.

After the changes, only modules required by at least one compilation step (which could be an arbitrary one instead of just of the descendants of the default step) will be analyzed by ZLS. This behavior is also seen in other language servers like rust-analyzer.

@leecannon
Copy link
Member

I have been using this for a couple days and have not hit any issues in a project with 58 “compilation units”.

@Techatrix
Copy link
Member

The build runner is only responsible to collect information that is directly associated with the build system. All further tasks like tying a file to a build.zig in part of the document store which already implemented with getAssociatedBuildFileUri and uriAssociatedWithBuild to find out whether a file is used by one of it's build system modules. This serves a similar purpose to what has been added to the build runner. This logic should instead be updated to return which module was responsible for the match.

But more importantly, while this PR appears offer better resolution of a root module or similar. It still has an inaccurate view of how compile steps and modules work in the build system. A proper solution should be able to handle these situations:

  • a compilation step only has a root module (modules form a graph not a list)
  • modules consist of a root source file and can import other modules
  • imported modules are not visible their parent module
  • a module can be part of multiple compilation steps (may be to complex to support)
  • a source file may be part of multiple modules by placing them in different compilation steps (may be to complex to support)

Keep in mind that the build runner code incorrectly uses the name "package" to refer to a "module".

I appreciate the effort that has been put into this but I rather reject this PR until a more complete solution has been implemented. I plan to work on this myself and I would not recommend working on such a comparatively large task to someone who is new to this codebase.

@Techatrix Techatrix closed this Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants